package com.baidumap.administrator.happystudy.ui;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;

import com.baidumap.administrator.happystudy.base.JsonTools;
import com.baidumap.administrator.happystudy.base.MyListView;
import com.baidumap.administrator.happystudy.base.Utils;
import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.adapter.RestauranFind1Adapter;
import com.baidumap.administrator.happystudy.adapter.RestauranFind2Adapter;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.Map;

public class RestauranFindActivity extends Activity {


    public ImageLoader loader;
    private MyListView mListView;
    private ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    private RestauranFind1Adapter mAdapter;
    private int pageNo = 1;
    private ArrayList<Map<String, Object>> arrayList;

    private MyListView mListView1;
    private ArrayList<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
    private RestauranFind2Adapter mAdapter1;
    private int pageNo1 = 1;
    private ArrayList<Map<String, Object>> arrayList1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_restauran_find);
        iniView();
    }
    private void iniView() {

        // LoadImage初始化
        loader = ImageLoader.getInstance();
        pageNo = 1;
        mListView = (MyListView) findViewById(R.id.list);
        mAdapter = new RestauranFind1Adapter(RestauranFindActivity.this, loader);
        new MyTask().execute("", "" + pageNo);// 线程加载json数据
        pageNo1 = 1;
        mListView1 = (MyListView) findViewById(R.id.list1);
        mAdapter1 = new RestauranFind2Adapter(RestauranFindActivity.this, loader);
        new MyTask1().execute("", "" + pageNo);// 线程加载json数据

    }

    class MyTask1 extends
            AsyncTask<String, Void, ArrayList<Map<String, Object>>> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

        }

        @Override
        protected ArrayList<Map<String, Object>> doInBackground(
                String... params) {

            ArrayList<Map<String, Object>> mList = null;
            mList = (ArrayList<Map<String, Object>>) JsonTools.listKeyMaps(
                    "list", Utils.HOUSE_JSON);
            return mList;
        }

        protected void onPostExecute(ArrayList<Map<String, Object>> result) {
            // TODO Auto-generated method stub

            list.addAll(result);//

            mAdapter.bindData(list);
            if (pageNo == 1) {

                mListView.setAdapter(mAdapter);
            }
            pageNo++;
            mAdapter.notifyDataSetChanged();
            super.onPostExecute(result);

        }
    }


    class MyTask extends
            AsyncTask<String, Void, ArrayList<Map<String, Object>>> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

        }

        @Override
        protected ArrayList<Map<String, Object>> doInBackground(
                String... params) {

            ArrayList<Map<String, Object>> mList = null;
            mList = (ArrayList<Map<String, Object>>) JsonTools.listKeyMaps(
                    "list", Utils.HOUSE_JSON);
            return mList;
        }

        protected void onPostExecute(ArrayList<Map<String, Object>> result) {
            // TODO Auto-generated method stub

            list1.addAll(result);//

            mAdapter1.bindData(list1);
            if (pageNo1 == 1) {

                mListView1.setAdapter(mAdapter1);
            }
            pageNo1++;
            mAdapter1.notifyDataSetChanged();
            super.onPostExecute(result);

        }
    }
}
